import { Component } from '@angular/core';
import { NavController,NavParams,AlertController } from 'ionic-angular';
import { HomePage } from '../home/home';
import { HttpService } from '../../providers/http.service';
import { constant } from '../../providers/config';
import { CommonFunc } from '../../providers/commonFunc';
/**
 * 维修历史
 */
@Component({
  templateUrl: 'help-history.html'
})
export class HelpHistory {
  private list : any;
  private elevatorId;
  private pageSize:number=10;
  private currentPage:number=1;
  private currentUserId:any;
  constructor(
    public navCtrl: NavController,
    private alertCtrl: AlertController,
    private httpService: HttpService,
    private navParams: NavParams,
    private commonFunc: CommonFunc
  ) {
    this.list =[
      {
        name:'星期一',
        time:'2019-09-08',
        type:'电梯困人12分钟，物业救人报警'
      },
      {
        name:'星期二',
        time:'2019-09-08',
        type:'电梯困人12分钟，物业救人报警'
      },
      {
        name:'星期三',
        time:'2019-09-08',
        type:'电梯困人12分钟，物业救人报警'
      },
      {
        name:'星期四',
        time:'2019-09-08',
        type:'电梯困人12分钟，物业救人报警'
      },
     

    ]
    this.elevatorId = this.navParams.get('elevatorId');
    
        let observable2 = this.httpService.queryEmergencyList({elevatorId: this.elevatorId,pageSize:this.pageSize, currentPage: this.currentPage});
         
        observable2.subscribe( data => {
          if(data.status==200){
            this.list = data.data.list;
          }
    
        });
       
      }
    
      //刷新
    doRefresh(refresher) {
      setTimeout(()=>{
          this.currentPage++;
          let params:any={};
          params.pageSize=this.pageSize+"";
          params.currentPage=this.currentPage+"";
          params.elevatorId = this.elevatorId;
          
          let ob = this.httpService.queryEmergencyList({elevatorId: this.elevatorId,pageSize:this.pageSize, currentPage: this.currentPage});
         
          ob.subscribe(data=>{
              if (data.status !=200) {
                  let toast = this.commonFunc.showInsideErrorToast(data.message);
                  toast.present();
                  return;
              }
              if(data.data.list.length<=0){
                  refresher.enable(false);
                  setTimeout(()=> {
                      refresher.enable(true);
                  },3000);
              }else{
                  data.data.list.forEach(e=>{
                      this.list.push(e);
                  });
              }
          });
    
          refresher.complete();
      },2000);
    
    }
      
    
    
    }